/**
 * @param {number[]} nums
 */
export var Solution = function (nums) {
  this.nums = nums
}

/**
 * @param {number} target
 * @return {number}
 */
Solution.prototype.pick = function (target) {
  let [ans, count] = [-1, 0]
  for (let i = 0; i < this.nums.length; i++) {
    if (this.nums[i] !== target) continue
    count++
    if (Math.random() * count < 1) ans = i
  }
  return ans
}

/**
 * Your Solution object will be instantiated and called as such:
 * var obj = new Solution(nums)
 * var param_1 = obj.pick(target)
 */
